//
//  CityData.swift
//  DollarBuy
//
//  Created by 郑东喜 on 2016/11/8.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit

class CityData: NSObject {
    
    static let shareInstance = CityData()
    
    
    var cityArrayData = NSArray()
    
    //省份索引
    let provinceIndex = 0
    
    //城市索引
    let cityIndex = 0
    
    //县城索引
    let areaIndex = 0
    
    
    func cityName(provinceIndex : Int) ->(provinceArray : NSArray,cityArray : NSArray,distinctArray : NSArray)  {
        let path = Bundle.main.path(forResource: "province_data", ofType: "json")
        let data = NSData(contentsOfFile: path!)!
        
        var proArray = NSArray()
        var cityArray = NSArray()
        var distinceArray = NSArray()
        do
        {
            let daaaa = try JSONSerialization.jsonObject(with: data as Data, options: JSONSerialization.ReadingOptions.allowFragments) as! NSDictionary
            
            let rootData = daaaa["root"]  as! NSDictionary
            //省份
            proArray = (rootData["pro"] as! NSArray)
            print(proArray)
            
//            proArray = proData
            
            print("\((#file as NSString).lastPathComponent):(\(#line)):(\("省份数组")))")
            //城市
            cityArray = (proArray[provinceIndex] as! NSDictionary)["cit"] as! NSArray
            
            
            //区
            distinceArray = ((((proArray[0] as! NSDictionary)["cit"] as! NSArray)[0] as! NSDictionary)["dis"]) as! NSArray

            
        } catch {
            
        }
        return (provinceArray : proArray,cityArray : cityArray,distinctArray : distinceArray)
    }
    

}
